package com.MLC.repository.impl;

import com.MLC.entity.Consultant;
import com.MLC.repository.ConsultantRepository;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class ConsultantRepositoryImpl implements ConsultantRepository {
    @Autowired
    private SessionFactory sessionFactory;
    private Session getCurrentSession() {
        return this.sessionFactory.getCurrentSession();
    }

    @Override
    public Consultant load(Long id) {
        return (Consultant) getCurrentSession().load(Consultant.class,id);
    }

    @Override
    public Consultant get(Long id) {
        return (Consultant) getCurrentSession().get(Consultant.class,id);
    }

    @Override
    public List<Consultant> findAll() {
        return null;
    }

    @Override
    public void persist(Consultant entity) {
        getCurrentSession().persist(entity);
    }

    @Override
    public Long save(Consultant entity) {
        Long ret=(Long)getCurrentSession().save(entity);
        return ret;
    }

    @Override
    public void saveOrUpdate(Consultant entity) {
        getCurrentSession().saveOrUpdate(entity);
    }

    @Override
    public void delete(Long id) {
        Consultant consultant = load(id);
        getCurrentSession().delete(consultant);
    }

    @Override
    public void flush() {
        getCurrentSession().flush();
    }
}
